from PySide2.QtWidgets import QApplication, QMessageBox, QComboBox
from PySide2.QtUiTools import QUiLoader
from tkinter import *
from tkinter.filedialog import *


class Stats:
    def __init__(self):
        # 从文件中加载UI定义

        # 从 UI 定义中动态 创建一个相应的窗口对象
        # 注意：里面的控件对象也成为窗口对象的属性了
        # 比如 self.ui.button , self.ui.textEdit
        self.ui = QUiLoader().load('UI/L1.ui')

        self.ui.inputBtn.clicked.connect(self.buttonClick)
        self.ui.lineEdit.returnPressed.connect(self.confirmBtnClick)

        self.ui.comboBox.addItems(['byhy', '白月黑羽', 'python教程'])
        self.ui.comboBox.currentIndexChanged.connect(self.selectChanged)
        self.ui.buttonGroup.buttonClicked.connect(self.radioClick)

        self.ui.actionopen.triggered.connect(self.openPageFile)

    def openPageFile(self):
        r = askopenfile(title = '打开文件', filetypes = [('Python', '*.py')])
        print(r)

    def radioClick(self):
        str = self.ui.buttonGroup.checkedButton().text()
        self.ui.textBrowser.append(str)

    def selectChanged(self):
        str = self.ui.comboBox.currentText()
        self.ui.textBrowser.append(str)

    def buttonClick(self):
        print("button click")
        print(self.ui.plainTextEdit.toPlainText())

    def confirmBtnClick(self):
        print('confirmBtnClick')
        print(self.ui.lineEdit.text())


app = QApplication([])
stats = Stats()
stats.ui.show()
app.exec_()
